SELECT tbl.table_schema, tbl.table_name
FROM information_schema.tables tbl
WHERE table_type = 'BASE TABLE'
AND table_schema NOT IN ('pg_catalog', 'information_schema')
AND NOT EXISTS (
SELECT 1
FROM information_schema.key_column_usage kcu
WHERE kcu.table_name = tbl.table_name
AND kcu.table_schema = tbl.table_schema
)
WITH cles_abs AS (
SELECT tbl.table_schema, tbl.table_name
FROM information_schema.tables tbl
WHERE table_type = 'BASE TABLE'
AND table_schema NOT IN ('pg_catalog', 'information_schema')
AND NOT EXISTS (
SELECT 1
FROM information_schema.key_column_usage kcu
WHERE kcu.table_name = tbl.table_name
AND kcu.table_schema = tbl.table_schema
)
)
SELECT 'ALTER TABLE' || table_schema || '.' || table_name
|| ' ADD COLUMN id INT4 GENERATED ALWAYS AS IDENTITY PRIMARY KEY;'
FROM cles_abs
ORDER BY table_schema, table_name;
pg_dumpall | gzip -c > fichier_sauvegarde.sql.gz
pg_dumpall -p 5432 -s | psql -p 5433 2> erreurs.txt
pg_dump -Fp -p 5432 -s -t "tbl_rast” -d base_raster > table_raster.sql
psql -p 5433 -f table_raster.sql -d base_raster 2> erreurs_raster.txt
psql -p 5432 -XAtqc "SELECT \$\$select setval('\$\$ || quote_ident(schemaname)||\$\$.\$\$|| quote_ident(sequencename) || \$\$', \$\$ || last_value || \$\$); \$\$ AS sql FROM pg_sequences" ma_base_1 \
| psql -p 5433 ma_base_1
Des questions ? #pgsession13